/**
 * org.assess.oa.system.action.TbRoleAction
 */
package org.assess.oa.system.action;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.assess.core.action.BaseAction;
import org.assess.core.service.ServiceResult;
import org.assess.oa.system.bean.TbRole;
import org.assess.oa.system.bean.TbSystem;
import org.assess.oa.system.service.TbRoleService;
import org.assess.oa.system.service.TbSystemService;

/**
 * @description 角色管理的Action实现类
 * @author XiaLongxiang
 * @createtime 2012-6-8 下午5:58:17
 */
public class TbRoleAction extends BaseAction {
    /** 序列化号 */
    private static final long serialVersionUID = 4565604885626602701L;
    
    /** TbRole的JavaBean对象 */
    private TbRole role;
    
    /** TbSystem的JavaBean对象 */
    private TbSystem system;
    
    /** 角色权限配置的显示值字符串 */
    private String roleString;
    
    /** 系统信息列表 */
    private List<TbSystem> systemList;
    
    /** 角色管理的Service层对象 */
    private TbRoleService tbRoleService;
    
    /** 系统管理的Service层对象 */
    private TbSystemService tbSystemService;
    
    /**
     * 跳转到角色管理的列表页面
     * @return
     */
    public String showRoleJsp() {
        return SUCCESS;
    }
    
    /**
     * 分页查询角色信息
     * @return
     */
    public String listRole() {
        String jsonString = this.tbRoleService.queryTbRoleAsList(super.getPage(), super.getRows(), role);
        super.setJsonString(jsonString);
        return SUCCESS;
    }
    
    /**
     * 加载角色信息，用户角色的编辑页面
     * @return
     */
    public String loadRole() {
        if (role != null && StringUtils.isNotBlank(role.getRole_id())) {
            super.setEdit(true);
            role = this.tbRoleService.queryTbRoleById(role);
        }
        else {
            super.setEdit(false);
        }
        return SUCCESS;
    }
    
    /**
     * 加载角色配置权限的信息，并跳转到配置权限页面
     * @return
     */
    public String loadConfigRole() {
        role = this.tbRoleService.queryTbRoleById(role);
        this.systemList = this.tbSystemService.queryTbSystemAsList(system);
        return SUCCESS;
    }
    
    /**
     * 保存角色信息
     * @return
     */
    public String saveRole() {
        try {
            ServiceResult result = this.tbRoleService.saveTbRole(role, super.isEdit());
            if (result == ServiceResult.save_success) {
                super.setMessage(super.getText("G_SAVE_001", new String[] {super.getText("ST_ROLE_000")}));
            }
            else {
                super.setMessage(super.getText("G_SAVE_002", new String[] {super.getText("ST_ROLE_000")}));
            }
        }
        catch (Exception ex) {
            super.setMessage(super.getText("G_SAVE_002", new String[] {super.getText("ST_ROLE_000")}));
        }
        
        return SUCCESS;
    }
    
    /**
     * 保存角色权限信息
     * @return
     */
    public String saveRolePermission() {
        try {
            String jsonString = this.tbRoleService.saveRolePermission(role, system, roleString);
            super.setJsonString(jsonString);
        }
        catch (Exception ex) {
            
        }
        
        return SUCCESS;
    }
    
    /**
     * 删除角色信息
     * @return
     */
    public String deleteRole() {
        if (role == null) {
            role = new TbRole();
        }
        
        role.setRole_id(super.getId());
        
        try {
            String jsonString = this.tbRoleService.deleteTbRole(role);
            super.setJsonString(jsonString);
        }
        catch (Exception ex) {
            
        }
        
        return SUCCESS;
    }
    
    public TbRole getRole() {
        return role;
    }
    
    public void setRole(TbRole role) {
        this.role = role;
    }
    
    public TbSystem getSystem() {
        return system;
    }
    
    public void setSystem(TbSystem system) {
        this.system = system;
    }
    
    public String getRoleString() {
        return roleString;
    }
    
    public void setRoleString(String roleString) {
        this.roleString = roleString;
    }
    
    public List<TbSystem> getSystemList() {
        return systemList;
    }
    
    public void setTbRoleService(TbRoleService tbRoleService) {
        this.tbRoleService = tbRoleService;
    }
    
    public void setTbSystemService(TbSystemService tbSystemService) {
        this.tbSystemService = tbSystemService;
    }
}
